<template>
  <div>
    <h1>User Info</h1>
    <p>User: {{ userName }}</p>
    <button @click="fetchUserInfo">Fetch User Info</button>
    
    <h1>Counter</h1>
    <p>Count: {{ count }}</p>
    <button @click="increment">Increment</button>
    <button @click="decrement">Decrement</button>
  </div>
</template>

<script setup>
import { useStore } from 'vuex';
import { computed } from 'vue';

// 获取 store
const store = useStore();

// 访问 user 模块的 state 和 getter
const userName = computed(() => store.getters['user/userName']);

// 访问 counter 模块的 state 和 mutation
const count = computed(() => store.getters['counter/count']);
const increment = () => store.commit('counter/increment');
const decrement = () => store.commit('counter/decrement');

// 调用 user 模块的 action
const fetchUserInfo = () => {
  store.dispatch('user/fetchUser');
};
</script>
